<template>
  <a-card
    :body-style="{ padding: '24px 48px' }"
    :bordered="false"
  >
    <h2 style="margin-bottom: 25px; font-size: 16px;">
      调度策略设置
    </h2>
    <p style="margin-bottom: 20px; font-size: 16px;">
      <label class="ant-form-item-required" />调度模型选择
    </p>

    <a-radio-group
      v-model="setting"
      style="margin-left: 5%;"
    >
      <a-radio
        class="setting-radio"
        :value="0"
      >
        最优成本代价模型
      </a-radio>
      <a-radio
        class="setting-radio"
        :value="1"
      >
        最优设备代价模型
      </a-radio>
      <a-radio
         class="setting-radio"
         :value="2"
      >
        最优能耗代价模型
     </a-radio>
     <a-radio
         class="setting-radio"
          :value="3"
      >
       配电子网均衡代价模型
      </a-radio>
    </a-radio-group>

    <div style="margin: 2% 0 0 8%;">
      <a-button
        type="primary"
        style="padding: 0 30px;"
        @click="setPolicy"
      >
        保存
      </a-button>
    </div>
  </a-card>
</template>

<script>
  import { getAction, gPostAction } from '@/api/manage'

  export default {
    name: 'F030302',
    data() {
      return {
        setting: ''
      }
    },
    mounted() {
      this.loadPolicySettings()
    },
    methods: {
      loadPolicySettings() {
        const postData = {}

        getAction("/scheduler/scheduler_model_list", postData).then((res) => {
          if (res.success) {
            const checkItem = res.data.filter(item => item.isCheck)
            if (checkItem.length > 0) {
              this.setting = checkItem[0].value
            }
          }
        })
      },
      setPolicy() {
        const postData = {
          type: this.setting
        }

        gPostAction('/scheduler/update_scheduler_model', postData).then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          }
        })
      }
    },
  }
</script>

<style
  lang="less"
  scoped
>
  .setting-radio {
    display: flex;
    align-items: center;
    height: 45px;
    line-height: 45px;
    font-size: 14px;

    /deep/ .ant-radio {
      margin-right: 10px;
    }
  }
</style>
